package com.yupi.springbootinit.model.vo;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.annotation.*;
import com.yupi.springbootinit.model.dto.question.QuestionContentDTO;
import com.yupi.springbootinit.model.entity.Question;
import lombok.Data;
import org.dom4j.bean.BeanAttribute;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 题目
 * @TableName question
 */
@Data
public class QuestionVO implements Serializable {

    private static final long serialVersionUID = 1L;
    /**
     * id
     */

    private Long id;

    /**
     * 题目内容（json格式）
     */
    private List<QuestionContentDTO> questionContentDTOList;

    /**
     * 应用 id
     */
    private Long appId;

    /**
     * 创建用户 id
     */
    private Long userId;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新时间
     */
    private Date updateTime;

    private UserVO userVO;



    public static QuestionVO objToVO(Question question) {
        if (question == null) {
            return null;
        }
        QuestionVO questionVO = new QuestionVO();
        BeanUtils.copyProperties(question,questionVO);
        String questionContent = question.getQuestionContent();
        questionVO.setQuestionContentDTOList(JSONUtil.toList(questionContent,QuestionContentDTO.class));
        return questionVO;
    }

    public static Question voToObj(QuestionVO questionVO) {
        if (questionVO == null) {
            return null;
        }
        Question question = new Question();
        BeanUtils.copyProperties(questionVO,question);
        List<QuestionContentDTO> questionContentDTOList1 = questionVO.getQuestionContentDTOList();
        question.setQuestionContent(JSONUtil.toJsonStr(questionContentDTOList1));
        return question;
    }


}